import { createRouter, createWebHistory } from 'vue-router'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    // {
    //   path: '/',
    //   meta: {
    //     title: '引导页',
    //     isLogin: true
    //   },
    //   component: () => import('@/views/guide/index.vue')
    // },
    {
      path: '/',
      redirect: '/home',
      component: () => import('@/views/layout/index.vue'),
      children: [
        {
          path: '/home',
          meta: {
            title: '首页'
          },
          component: () => import('@/views/home/index.vue')
        },
        {
          path: '/patient',
          meta: {
            title: '病友圈'
          },
          component: () => import('@/views/patient/index.vue')
        },
        {
          path: '/video',
          meta: {
            title: '视频'
          },
          component: () => import('@/views/video/index.vue')
        }
      ]
    },
    {
      path: '/my',
      meta: {
        title: '我的'
      },
      component: () => import('@/views/my/index.vue')
    },
    {
      path: '/wallet',
      meta: {
        title: '钱包'
      },
      component: () => import('@/views/wallet/index.vue')
    },
    {
      path: '/consultation',
      meta: {
        title: '问诊'
      },
      component: () => import('@/views/consultation/index.vue')
    },
    {
      path: '/inqDetail',
      meta: {
        title: '问诊详情'
      },
      component: () => import('@/views/inqDetail/index.vue')
    },
    {
      path: '/review',
      meta: {
        title: '评论详情'
      },
      component: () => import('@/views/review/index.vue')
    },
    {
      path: '/login',
      meta: {
        title: '登录',
        isLogin: true
      },
      component: () => import('@/views/login/index.vue')
    },
    {
      path: '/register',
      meta: {
        title: '注册',
        isLogin: true
      },
      component: () => import('@/views/register/index.vue')
    },
    {
      path: '/forget1',
      meta: {
        title: '忘记密码1',
        isLogin: true
      },
      component: () => import('@/views/forget1/index.vue')
    },
    {
      path: '/forget2',
      meta: {
        title: '忘记密码2',
        isLogin: true
      },
      component: () => import('@/views/forget2/index.vue')
    },
    {
      path: '/result',
      meta: {
        title: '病友圈搜索结果'
      },
      component: () => import('@/views/result/index.vue')
    },
    {
      path: '/information',
      meta: {
        title: '用户信息'
      },
      component: () => import('@/views/information/index.vue')
    },
    {
      path: '/detail/:id',
      meta: {
        title: '病友圈详情页'
      },
      name: 'DetailPage',
      component: () => import('@/views/detail/index.vue')
    },
    {
      path: '/publishSickCircle',
      meta: {
        title: '发布病友圈'
      },
      component: () => import('@/views/publishSickCircle/index.vue')
    },
    // {
    //   path: '/comment/:id/:name',
    //   meta: {
    //     title: '评论'
    //   },
    //   name: 'comment',
    //   component: () => import('@/views/comment/index.vue')
    // },
    {
      path: '/search',
      meta: {
        title: '搜索'
      },
      component: () => import('@/views/search/index.vue')
    },
    {
      path: '/mywallet',
      meta: {
        title: '我的钱包'
      },
      component: () => import('@/views/mywallet/index.vue')
    },
    {
      path: '/recharge',
      meta: {
        title: '充值'
      },
      component: () => import('@/views/recharge/index.vue')
    },
    {
      path: '/success',
      meta: {
        title: '充值成功'
      },
      component: () => import('@/views/success/index.vue')
    },
    {
      path: '/withdrawal',
      meta: {
        title: '提现'
      },
      component: () => import('@/views/withdrawal/index.vue')
    },
    {
      path: '/record',
      meta: {
        title: '提现记录'
      },
      component: () => import('@/views/record/index.vue')
    },
    {
      path: '/progress',
      meta: {
        title: '提现中'
      },
      component: () => import('@/views/progress/index.vue')
    },
    {
      path: '/disease',
      meta: {
        title: '常见病症'
      },
      component: () => import('@/views/disease/index.vue')
    },
    {
      path: '/medicine',
      meta: {
        title: '常见药品'
      },
      component: () => import('@/views/medicine/index.vue')
    },
    {
      path: '/medicineDetail/:id',
      meta: {
        title: '药品详情'
      },
      component: () => import('@/views/medicineDetail/index.vue')
    },
    {
      path: '/diseaseDetail/:id',
      meta: {
        title: '病症详情'
      },
      component: () => import('@/views/diseaseDetail/index.vue')
    },
    // {
    //   path: '/patient_search',
    //   meta: {
    //     title: '病友圈搜索'
    //   },
    //   component: () => import('@/views/patient_search/index.vue')
    // },
    {
      path: '/current',
      meta: {
        title: '当前问诊'
      },
      component: () => import('@/views/current/index.vue')
    },
    {
      path: '/chat',
      meta: {
        title: '聊天'
      },
      component: () => import('@/views/chat/index.vue')
    },
    {
      path: '/history',
      meta: {
        title: '历史问诊'
      },
      component: () => import('@/views/history/index.vue')
    },
    {
      path: '/files',
      meta: {
        title: '我的档案'
      },
      component: () => import('@/views/files/index.vue')
    },
    {
      path: '/suggestion',
      meta: {
        title: '被采纳建议'
      },
      component: () => import('@/views/suggestion/index.vue')
    },
    {
      path: '/interest',
      meta: {
        title: '我的关注'
      },
      component: () => import('@/views/interest/index.vue')
    },
    {
      path: '/task',
      meta: {
        title: '我的任务'
      },
      component: () => import('@/views/task/index.vue')
    },
    {
      path: '/manage',
      meta: {
        title: '设备管理'
      },
      component: () => import('@/views/manage/index.vue')
    },
    {
      path: '/collect',
      meta: {
        title: '我的收藏'
      },
      component: () => import('@/views/collect/index.vue')
    },
    {
      path: '/bank',
      meta: {
        title: '银行卡'
      },
      component: () => import('@/views/bank/index.vue')
    },
    {
      path: '/gender',
      meta: {
        title: '性别'
      },
      component: () => import('@/views/gender/index.vue')
    },
    {
      path: '/binding',
      meta: {
        title: '绑定银行卡'
      },
      component: () => import('@/views/binding/index.vue')
    },
    {
      path: '/homeSearch',
      meta: {
        title: '首页搜索'
      },
      component: () => import('@/views/homeSearch/index.vue')
    },
    {
      path: '/signs',
      meta: {
        title: '体征'
      },
      component: () => import('@/views/signs/index.vue')
    },
    {
      path: '/checkBank',
      meta: {
        title: '查看银行卡'
      },
      component: () => import('@/views/checkBank/index.vue')
    },
    {
      path: '/more',
      meta: {
        title: '查看更多'
      },
      component: () => import('@/views/more/index.vue')
    },

    {
      path: '/moreDetail',
      meta: {
        title: '资讯详情页'
      },
      component: () => import('@/views/moreDetail/index.vue')
    },
    {
      path: '/nickname',
      meta: {
        title: '修改昵称'
      },
      component: () => import('@/views/nickname/index.vue')
    },
    {
      path: '/modify',
      meta: {
        title: '修改密码'
      },
      component: () => import('@/views/modify/index.vue')
    },
    {
      path: '/checkInformation',
      meta: {
        title: '查看银行卡信息'
      },
      component: () => import('@/views/checkInformation/index.vue')
    },
    {
      path: '/add',
      meta: {
        title: '添加'
      },
      component: () => import('@/views/add/index.vue')
    },
    {
      path: '/edit',
      meta: {
        title: '编辑'
      },
      component: () => import('@/views/edit/index.vue')
    },
    {
      path: '/authentication',
      meta: {
        title: '实名认证'
      },
      component: () => import('@/views/authentication/index.vue')
    },
    {
      path: '/myMessage',
      meta: {
        title: '我的消息'
      },
      component: () => import('@/views/myMessage/index.vue')
    },
    {
      path: '/release',
      meta: {
        title: '发布病友圈'
      },
      component: () => import('@/views/release/index.vue')
    },
    {
      path: '/informationDetail/:id',
      meta: {
        title: '资讯详情'
      },
      component: () => import('@/views/informationDetail/index.vue')
    },
    {
      path: '/evaluate_box',
      meta: {
        title: '评价服务'
      },
      component: () => import('@/views/evaluate_box/index.vue')
    },
    {
      path: '/purchase',
      meta: {
        title: '我购买的视频'
      },
      component: () => import('@/views/purchase/index.vue')
    },
    {
      path: '/screen',
      meta: {
        title: '屏幕亮度'
      },
      component: () => import('@/views/screen/index.vue')
    },
    {
      path: '/vrsion',
      meta: {
        title: '版本检测'
      },
      component: () => import('@/views/vrsion/index.vue')
    },
    {
      path: '/mypatient',
      meta: {
        title: '我的病友圈'
      },
      component: () => import('@/views/mypatient/index.vue')
    },
    {
      path: '/invite',
      meta: {
        title: '邀请页面'
      },
      component: () => import('@/views/invite/index.vue')
    },
    {
      path: '/system',
      meta: {
        title: '系统消息'
      },
      component: () => import('@/views/system/index.vue')
    },
    {
      path: '/consultationmessage',
      meta: {
        title: '问诊消息'
      },
      component: () => import('@/views/consultationmessage/index.vue')
    },
    {
      path: '/entry',
      meta: {
        title: 'H币入账消息'
      },
      component: () => import('@/views/entry/index.vue')
    },
    {
      path: '/evaluate_detail',
      meta: {
        title: '查看评价详情'
      },
      component: () => import('@/views/evaluate_detail/index.vue')
    },
    {
      path: '/evaluation_results',
      meta: {
        title: '评价结果'
      },
      component: () => import('@/views/evaluation_results/index.vue')
    },
    {
      path: '/checkauthentication',
      meta: {
        title: '查看认证信息'
      },
      component: () => import('@/views/checkauthentication/index.vue')
    },
    {
      path: '/commentlist',
      meta: {
        title: '评论列表'
      },
      component: () => import('@/views/commentlist/index.vue')
    },
    {
      path: '/tu',
      meta: {
        title: '图'
      },
      component: () => import('@/views/tu/index.vue')
    },
    {
      path: '/imagks',
      meta: {
        title: '懒加载+裂图'
      },
      component: () => import('@/views/imagks/index.vue')
    },
    {
      path: '/dummy',
      meta: {
        title: '虚拟列表'
      },
      component: () => import('@/views/dummy/index.vue')
    },
    {
      path: '/tu1',
      meta: {
        title: '虚拟列表'
      },
      component: () => import('@/views/tu1/index.vue')
    },
    // {
    //   path: '/three',
    //   meta: {
    //     title: '3D'
    //   },
    //   component: () => import('@/views/three/index.vue')
    // },
    {
      path: '/baidu',
      meta: {
        title: '地图'
      },
      component: () => import('@/views/baidu/index.vue')
    }
  ]
})

// // 路由守卫
router.beforeEach((to, from, next) => {
  // 获取Token
  const token = localStorage.getItem('result') // 如果没有Token，则跳转到登录页
  if (to.meta.isLogin) {
    next()
  } else {
    if (!token && to.path !== '/login') {
      next('/login')
    } else {
      next()
    }
  }
})

export default router
